// messagesdlg.h : interface of the CDraftsDlg class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

#include "DraftsDb.h"
#include "ExListViewCtrl.h"

class CDraftsDlg
    : public CStdDialogResizeImplCancel<CDraftsDlg>
{
public:
    CDraftsDlg(void);

    enum { IDD = IDD_DRAFTS };

    BEGIN_DLGRESIZE_MAP(CDraftsDlg)
        DLGRESIZE_CONTROL(IDC_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y)
    END_DLGRESIZE_MAP()

    BEGIN_MSG_MAP(CDraftsDlg)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
        MESSAGE_HANDLER(WM_SIZE, OnSize)
        NOTIFY_HANDLER(IDC_LIST, NM_CLICK, OnListClick)
        NOTIFY_HANDLER(IDC_LIST, NM_DBLCLK, OnListDblClick)
        NOTIFY_HANDLER(IDC_LIST, NM_RETURN, OnListReturn)
        COMMAND_ID_HANDLER(ID_MENU_NEW, OnMenuNew)
        COMMAND_ID_HANDLER(ID_MENU_DELETE, OnMenuDelete)
        CHAIN_MSG_MAP(CStdDialogResizeImplCancel<CDraftsDlg>)
        REFLECT_NOTIFICATIONS()
    END_MSG_MAP()

    inline UINT GetDraftId(void)
    { return m_DraftId; }

    inline void SetSelectMode(bool Mode = true)
    { m_SelectMode = Mode; }

private:

    // Handler prototypes (uncomment arguments if needed):
    //	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    //	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
    //	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

    LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);
    LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);
    LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);

    LRESULT OnListClick(int idCtrl, LPNMHDR pnmh, BOOL& /*bHandled*/);
    LRESULT OnListDblClick(int idCtrl, LPNMHDR pnmh, BOOL& /*bHandled*/);
    LRESULT OnListReturn(int idCtrl, LPNMHDR pnmh, BOOL& /*bHandled*/);

    LRESULT OnMenuNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnMenuDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

    void AddNewDraft(void);
    void AddDraft(UINT DraftId, CString &Draft);
    void EditDraft(int ListIndex, UINT DraftId);
    DWORD FormatDraft(CString *pDraft);

    void OnSize(void);
    void OnItem(int ItemId);

    CImageList m_ImageList;
    CExListViewCtrl m_List;
    CDraftsDb m_DraftsDb;
    UINT m_DraftId;
    bool m_SelectMode;
};
